document.write('<script src="helper.js"></script>');
function testUser(){
	testRegister();
	testLogin();
	testGetUsers();
	testIsAdmin();
	testGetInfo();
	testIsLoggedIn();
	testPromoteUser();
	testDemoteUser();
	testEditInfo();
	testGetMyProject();
	testLogout();
}
var g_user_id;

function testRegister(){
	write("Testing register");
	var email = new Date();
	var password = "lanevo6tmegsr"; 
	var h_pw = hex_md5(password);
	var firstName = "Jason";
	var lastName = "Tsao";
	var info = {"email" : email,"password" : h_pw, "firstName" : firstName, "lastName" : lastName}
	var ret = get("userApi.php","register",info);
	g_user_id = ret.userId;
	write(ret.success);
	
}
function testLogin(){
	write("Testing Login");
	var userName = "smoj33@gmail.com";
	var pw = "aaaa";
	var h_pw = hex_md5(pw);
	var info = {"email" : userName,"password" : h_pw, "remember" : 1}
	var ret = get("userApi.php","login",info);
	write((ret.userId >= 0));
}
function testIsAdmin(){
		write("Testing isAdmin");
		info = {};
		var ret = get("userApi.php","isAdmin",info);
		write(ret.success);
	}
	
function testGetInfo(){
		write("Testing getInfo");
		var info = {};
		var ret = get("userApi.php","getInfo",info);
		write(ret.success);

}
	
function testIsLoggedIn(){
		write("Testing isLoggedIn");
		var info = {};
		var ret = get("userApi.php","isLoggedIn",info);
		write(ret.success);
}
	
function testPromoteUser(){
		write("Testing promoteUser");
		var userID = g_user_id;
		var info = {"userId" : userID};
		var ret = get("userApi.php","promoteUser",info);
		write(ret.success);
		
		write("Testing promoteUser as not admin");
		helperLogout();
		helperLogin(false);
		var info = {"userId" : "test@test.com"}
		var ret = get("userApi.php", "promoteUser", info);
		write(!ret.success);
		
		helperLogin(true);
}

function testDemoteUser(){
		write("Testing demoteUser");
		var userID = g_user_id;
		var info = {"userId" : userID};
		var ret = get("userApi.php","promoteUser",info);
		write(ret.success);
		
		write("Testing demoteUser as not admin");
		helperLogout();
		helperLogin(false);
		var info = {"userId" : "test@test.com"}
		var ret = get("userApi.php", "demoteUser", info);
		write(!ret.success);
		
		helperLogin(true);
}

function testEditInfo(){

	write("Testing editInfo");
	var email = "smoj33@gmail.com";
	var password = "aaaa";
	var h_pw = hex_md5(password);
	var firstName = new Date();
	var lastName = "Mojtobai";
	var info = {"firstName" : firstName};
	var ret = get("userApi.php","editInfo",info);
	write (ret.success);
	write (ret.message);

}

function testGetMyProject(){
	write("Testing getMyProject");
	var info = {};
	var ret = get("userApi.php", "getMyProject", info);
	write(ret.message);

}

function testLogout(){
	write("Testing Logout");
	var info = {}
	var ret = get("userApi.php","logout",info);
	write(ret.success);
	helperLogin(true);

}






